import React, {Component} from 'react';
import './index.css'

class Footer extends Component {
    //全选
    handCheckAll = (event) => {
        this.props.handCheckAll(event.target.checked)
    }

    //清除已完成的
    clearAll = () => {
        this.props.clearAll();
    }

    render() {
        let {todos} = this.props;
        //已完成个数
        let doneCount = todos.reduce((pre, current) => pre + (current.done ? 1 : 0), 0)
        //总数
        let total = todos.length
        return (
            <div className="todo-footer">
                <label>
                    <input checked={doneCount === total && total !== 0}
                           onChange={this.handCheckAll} type="checkbox"/>
                </label>
                <span>
                    <span>已完成{doneCount}</span> / 全部{total}
                </span>
                <button onClick={this.clearAll} className="btn btn-danger">清除已完成任务</button>
            </div>
        );
    }
}

export default Footer;